
const ComponentsConfig = require("./components/componentsConfig");
const CacheConfigItem = require("./utils/cacheCenter/models/cacheConfigItem");
const RequestConfig = require("./utils/request/requestConfig");
const Validator = require("./utils/validator");
class ConfigModel {
    constructor(param) {
        const {
            projectName='', // String Project name
            defaultShareTitle = '', // String title
            defaultSharePagePath='', // String page path
            cacheConfig = [], // Array<CacheConfigItem>
            requestConfig = {}, // RequestConfig
            componentsConfig = {}, // ComponentsConfig
        } = param || {}
        this.projectName = projectName;
        this.defaultShareTitle=defaultShareTitle;
        this.defaultSharePagePath = defaultSharePagePath;
        this.cacheConfig = cacheConfig.map(item => {
            return new CacheConfigItem(item)
        })
        this.requestConfig = new RequestConfig.default(requestConfig)
        this.componentsConfig = new ComponentsConfig.default(componentsConfig);

        valid.call(this);
    }
}

function valid() {
    let validator = new Validator();
    validator.add(this.requestConfig, "isNotEmpty", "leeCommonJs请配置请求配置");
    let errMsg = validator.start();
    if (errMsg) {
        throw new Error(errMsg);
    }
}

module.exports = ConfigModel;